/*
 * XYCircle.java
 *
 * Created on September 17, 2004, 1:10 PM
 */

package edu.temple.GUS.MMA.Neighborhoods;
import java.lang.Math;

/**
 *
 * @author  jeffleon
 */
public class XYCircle extends XYNeighborhood{
    
    private int radius;
    
    private boolean filter[][];
    
    /** Creates a new instance of XYCircle */
    public XYCircle(int r) {
        
        // Define the x and y extend of the neighborhood
        super(2*r+1, 2*r+1);
        radius = r;
        
        float distance;
        int kernelXCoord = r;
        int kernelYCoord = r;
        
        // Create a circular filter
        filter = new boolean[2*radius+1][2*radius+1];
        
        for (int j=0; j<=2*radius; j++)
            for (int i=0; i<=2*radius; i++)
            {
                distance = (float)Math.sqrt((j-kernelYCoord) * (j-kernelYCoord) + (i-kernelXCoord) * (i-kernelXCoord));
                if ( distance <= (float)radius)
                    filter[j][i] = true;
                else
                    filter[j][i] = false;
            }
    }
    
    public int getRadius() { return radius; }
    public void putRadius(int r) { radius = r; }
    public boolean getFilterElement(int x, int y) { return filter[y][x];}
}
